import { get } from "../../utils/db"
Page({
    data: {
        list: [],
        pageSize: 3, //设置煤业显示的个数
        page:1,
        recipes:[]
    },
    async onLoad() {
        this.getPage() //调用获取列表方法
        var result = await get("menu");   //读取数据信息
        this.setData({
            list: result.data
        })
    },
    toDetail(e) {
        var id = e.currentTarget.id
        wx.navigateTo({
            url: '/pages/detail/detail?id=' + id,
        })
    },
    // 页面触底
    onReachBottom() {
      this.data.page+=1;  //滚动触底,page累加
      this.getPage() //获取页面数据
    },
	async getPage(){
        var pageSize=this.data.pageSize; //每页多少个数据
        var page =this.data.page;
        var skip=(page-1)*pageSize; //跳过多少条
        let res=await get('menu',{status:1},skip,pageSize)
        let arr=res.data;
        // console.log(arr);
        this.setData({
            recipes:this.data.recipes.concat(arr)	//新数据和旧数据进行拼接
        })
    }
})

